'''
Created on Sep 3, 2011

@author: david
'''
from google.appengine.ext import db

# System User Roles
SHOPPER_ROLE = 1
DEALER_ROLE = 2
ADMIN_ROLE = 16
JEDI_ROLE = 255

#--------------------------
# general server stuff
#--------------------------
class Account(db.Model):
    # properties
    name = db.StringProperty()
    uid = db.EmailProperty()
    pwd = db.StringProperty()
    role = db.IntegerProperty(default=1)
    status = db.IntegerProperty()
    dt_open = db.DateTimeProperty(auto_now_add = True)
    dt_last = db.DateTimeProperty(auto_now_add = True)
    aid = db.StringProperty()

    def toDict(self):
        return ({'uid': self.uid, 'name': self.name, 'status': self.status, 'role': self.role})

#--------------------------
# Payment Ranger Domain
#--------------------------
class Dealer(db.Model):
    # properties
    name = db.StringProperty()
    uid = db.EmailProperty()
    pwd = db.StringProperty()
    status = db.IntegerProperty()
    url = db.URLProperty()
    usr_uri = db.StringProperty()
    proc_uri = db.StringProperty()
    buyit_addr = db.EmailProperty()
    buyit_phone = db.PhoneNumberProperty()
    dt_open = db.DateTimeProperty(auto_now_add = True)
    dt_last = db.DateTimeProperty(auto_now_add = True)
    did = db.StringProperty()

class DealerAccount(db.Model):
    did = db.StringProperty()
    aid = db.StringProperty()
    pid = db.IntegerProperty(default=0)
    role = db.IntegerProperty()

class RangerEvent(db.Model):
    pkey = db.IntegerProperty(default=0)
    evtype = db.IntegerProperty(default=1)
    did = db.StringProperty()
    pid = db.IntegerProperty(default=0)
    vin = db.StringProperty()
    descr = db.StringProperty()
    tmstmp = dt_open = db.DateTimeProperty(auto_now_add = True)

    def addBuyEvent(self):
        c = EventLog(pkey=self.key,evtype=2,did=self.did,pid=self.pid,vin=self.vin,descr='Buy Notification')
        c.put()
        return c
